package com.wdc.deliveryrobot.adapter;

import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wdc.deliveryrobot.R;
import com.wdc.deliveryrobot.model.Line;

import org.w3c.dom.Text;

import java.util.List;

/**
 * @Author: tianHuiDa
 * @Date: 2024/11/17
 * @Description: 巡航模式所有点位显示
 */
public class CruisePointAdapter extends RecyclerView.Adapter<CruisePointAdapter.ViewHolder> {

    private List<String> point;

    private OnItemClickListener listener;

    public CruisePointAdapter(List<String> list,OnItemClickListener listener){
        this.point = list;
        this.listener = listener;
    }

    public interface OnItemClickListener{
        void clickButton(String name);
    }


    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.point, parent, false);
        return new CruisePointAdapter.ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        String name = point.get(position);
        holder.textView.setText(name);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //选中数据

                if (listener != null){
                    listener.clickButton(name);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return point.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{
        public TextView textView;

        public ViewHolder(View itemView){
            super(itemView);
            textView = itemView.findViewById(R.id.text);
        }


    }
}
